package com.hl.card.modular.pack.controller;

import com.hl.card.common.controller.BaseController;
import com.hl.card.common.persistence.model.Goods;
import com.hl.card.common.persistence.model.ProfitScale;
import com.hl.card.common.persistence.model.SalesDivision;
import com.hl.card.modular.packBack.service.GoodsSevice;
import com.hl.card.modular.packBack.service.IProfitScaleService;
import com.hl.card.modular.packBack.service.ISalesDivisionService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/api/goods")
@RestController
public class GoodsDivsionController  extends BaseController {

    @Resource
    private GoodsSevice goodsSevice;

    @Resource
    private IProfitScaleService iProfitScaleService;

    @Resource
    private ISalesDivisionService iSalesDivisionService;


    @RequestMapping(value = "/queryByCode",method = RequestMethod.POST)
    public Object queryByCode(String goodsCode){

        Map<String,Object> map = new HashMap<>();

        SalesDivision salesDivision = iSalesDivisionService.selectByName(goodsCode);
        if(salesDivision == null){
            map.put("code",202);
            map.put("msg","该产品消费分润比例不存在");
            return  map;

        }
        ProfitScale profitScale = iProfitScaleService.selectByName(goodsCode);
        if(profitScale == null){
            map.put("code",203);
            map.put("msg","该产品销售分润比例不存在");
            return  map;
        }

        map.put("code",200);
        map.put("msg","查询成功");
        Map<String,Object> result = new HashMap<>();
        result.put("profitScale",profitScale);
        result.put("salesDivision",salesDivision);
        map.put("data",result);
        return  map;

    }

    @RequestMapping(value = "/queryGoods",method = RequestMethod.POST)
    public Object queryGoods(String code){
        Map<String,Object> map = new HashMap<>();
        Goods goods = goodsSevice.selectByCode(code);
        if(goods == null){
            return super.FailuerTip("产品代码不存在");

        }else{
            map.put("code",200);
            map.put("data",goods);
            map.put("message","查询成功");
            return  map;
        }

    }
    @RequestMapping(value = "/queryGoodsList",method = RequestMethod.GET)
    public Object queryGoodsList(){
        Map<String,Object> map = new HashMap<>();
        List<Map<String, Object>> list = goodsSevice.selectList();
        if(list == null || list.size() == 0){
            return super.FailuerTip("查询结果为空");
        }else{
            map.put("code",200);
            map.put("data",list);
            map.put("message","查询成功");
            return  map;
        }


    }





}
